/*
  Name:        PixelMap.h
  Copyright:   Version 0.1
  Author:      Rodrigo Luis de Souza da Silva
  Date:        04/07/2009
  Description: Simple class to load BMP images and modify its data.
               You can create an image manually and convert it to a
               pixel matrix and vice-versa.
*/

#ifndef __PIXEL_MAP_H__
#define __PIXEL_MAP_H__

//////////////////////////////////////////////////////////////////
// Preprocessor directives
#define GLUT_NO_LIB_PRAGMA
#define GLUT_NO_WARNING_DISABLE
#define GLUT_DISABLE_ATEXIT_HACK

//////////////////////////////////////////////////////////////////
// New types
typedef char Byte;
typedef unsigned char uByte;

//////////////////////////////////////////////////////////////////
// Classes

// Simple pixel Structure
struct pixel
{
   uByte value;      // Grayscale value
   uByte R, G, B, A; // Color RGBA values
};

// Pixel map class
class PixelMap
{
   public:
      // Constructors and Destructors
      PixelMap(const char *fname);
      PixelMap();
      ~PixelMap();

      // Read image from a bitmap file
      void Read(const char *fname);

      // Create image from a 'uByte' array
      void CreateImage(int w, int h, uByte *d);

      // view stored image
      void ViewImage();

      // Modify and get pixel information
      uByte  pixel_elem(int x, int y, int elem);
      uByte *pixel_pos(int x, int y);

      // Set/Get image's width and height
      int  GetWidth();
      void SetWidth( int);
      int  GetHeight();
      void SetHeight( int);

      // Set/Get image data
      uByte* GetData();
      void   SetData(uByte*);

      // Convertion methods
      void ConvertPixelsToData(pixel **m);
      void ConvertDataToPixels(pixel **m);
      void ConvertToGrayScale();

   public:
      int width, height;
      uByte *data;
      bool grayScale;
};

#endif
